package com.qiku.utils;

import com.qiku.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

    /**
     * 获取Authentication
     * @return
     */
    public static Authentication getAuthentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }
    /**
     * 获取用户
     * @return
     */
    public static LoginUser getLoginUser(){
        return (LoginUser)getAuthentication().getPrincipal();
    }

    public static Boolean isAdmin(){
        Long id = getLoginUser().getUser().getId();
        return 1L == id && null != id;
    }
    public static Long getUserId(){
       return getLoginUser().getUser().getId();
    }
}
